<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<h1>GET</h1>
		<button type="button" onclick="gettime()">获取当前日期和时间</button>
		<br />
		<button type="button" onclick="getpoem()">随机一句名言</button>
		<br />
		<button type="button" onclick="getauthor()">获取5行诗词列表-包含作者信息</button>
		<br />
		<button type="button" onclick="getpoetry()">获取诗词列</button>
		<br />
		<button type="button" onclick="getlist()">平台接口预览</button>
		<br />
		<h1>POST</h1>
		<button type="button" onclick="postfeedback()">用户反馈</button>
		<br />
		<button type="button" onclick="postpicture()">美图推荐</button>
		<br />
		<button type="button" onclick="postparagraph()">段子详情</button>
		<br />
		<button type="button" onclick="postnwes()">获取网易新闻</button>
		<br />
		<h1>结果</h1>
		<div id="maxdiv"></div>
	</body>
	<script type="text/javascript">
		function gettime(){
			var ajax = new XMLHttpRequest();
			ajax.open('GET','http://poetry.apiopen.top/getTime');
			ajax.send();
			ajax.onreadystatechange = function(){
				if(ajax.status == 200 && ajax.readyState==4){
					var obj = JSON.parse(ajax.responseText);
					var maxdiv = document.getElementById('maxdiv');
					console.log(obj.result)
					maxdiv.innerText = obj.result.dateTime;
				}
			}
		}
		function getpoem(){
			var ajax = new XMLHttpRequest();
			ajax.open('GET','http://poetry.apiopen.top/sentences');
			ajax.send();
			ajax.onreadystatechange = function(){
				if(ajax.status == 200 && ajax.readyState==4){
					var obj = JSON.parse(ajax.responseText);
					var maxdiv = document.getElementById('maxdiv');
					console.log(obj.result)
					var sum = obj.result.name+'——'+obj.result.from
					maxdiv.innerText = sum;
				}
			}
		}
		function getauthor(){
			var ajax = new XMLHttpRequest();
			ajax.open('GET','http://poetry.apiopen.top/poetryFull?count=5&page=1');
			ajax.send();
			ajax.onreadystatechange = function(){
				if(ajax.status == 200 && ajax.readyState==4){
					var obj = JSON.parse(ajax.responseText);
					var sum = '';
					for(var i=0;i<obj.result.length;i++){
						sum = sum + '<h3>' + obj.result[i].title + '</h3>' + obj.result[i].simpleIntro + '<br />';
					}
					console.log(sum);
					var maxdiv = document.getElementById('maxdiv');
					console.log(obj.result)
					maxdiv.innerHTML = sum;
				}
			}
		}
		function getpoetry(){
			var ajax = new XMLHttpRequest();
			ajax.open('GET','http://poetry.apiopen.top/poetry?count=3&page=1');
			ajax.send();
			ajax.onreadystatechange = function(){
				if(ajax.status == 200 && ajax.readyState==4){
					var obj = JSON.parse(ajax.responseText);
					var sum = '';
					for(var i=0;i<obj.result.length;i++){
						sum = sum + obj.result[i].title + '<br />';
						console.log(sum);
					}
					var maxdiv = document.getElementById('maxdiv');
					console.log(obj)
					maxdiv.innerHTML = sum;
				}
			}
		}
		function getlist(){
			var ajax = new XMLHttpRequest();
			ajax.open('GET','https://api.apiopen.top/getAllUrl');
			ajax.send();
			ajax.onreadystatechange = function(){
				if(ajax.status == 200 && ajax.readyState==4){
					var obj = JSON.parse(ajax.responseText);
					var sum = '';
					for(var i=0;i<obj.length-1;i++){
						sum = sum + obj[i] + '<br />';
					}
					var maxdiv = document.getElementById('maxdiv');
					console.log(obj)
					maxdiv.innerHTML = sum;
				}
			}
		}
		function postfeedback(){
			var ajax = new XMLHttpRequest();
			ajax.open('POST','https://api.apiopen.top/userFeedback');
			ajax.setRequestHeader('Content-type','application/x-www-form-urlencoded')
			ajax.send('apikey=9648872f9aa08da137ce45fe1dda8279&text=我觉得应该再增加个版本更新功能。&email=135@qq.com');
			ajax.onreadystatechange = function(){
				if(ajax.status == 200 && ajax.readyState==4){
					var obj = JSON.parse(ajax.responseText);
					console.log(obj);
					if(obj.code == 400){
						alert('反馈信息不能为空!');
					}
				}
			}
		}
		function postpicture(){
			var ajax = new XMLHttpRequest();
			var maxdiv = document.getElementById('maxdiv');
			ajax.open('POST','https://api.apiopen.top/getImages');
			ajax.setRequestHeader('Content-type','application/x-www-form-urlencoded');
			ajax.send('page=1&count=5');
			ajax.onreadystatechange = function(){
				if(ajax.status == 200 && ajax.readyState==4){
					var obj = JSON.parse(ajax.responseText);
					var sum = '';
					console.log(obj.result);
					for(var i=0;i<obj.result.length;i++){
						sum = sum + `<img src="`+obj.result[i].img+`" >`+`<br/>`
						console.log(sum)
					}
					maxdiv.innerHTML = sum;
				}
			}
		}
		function postparagraph(){
			var ajax = new XMLHttpRequest();
			var maxdiv = document.getElementById('maxdiv');
			ajax.open('POST','https://api.apiopen.top/getJoke');
			ajax.setRequestHeader('Content-type','application/x-www-form-urlencoded');
			ajax.send('count=10');
			ajax.onreadystatechange = function(){
				if(ajax.status == 200 && ajax.readyState==4){
					var obj = JSON.parse(ajax.responseText);
					var sum = '';
					console.log(obj.result);
					for(var i=0;i<obj.result.length;i++){
						sum = sum +`<img src="`+obj.result[i].images+`" >`+`<br/>`+obj.result[i].name +`：`+ obj.result[i].text +`<br/>`;
					}
					maxdiv.innerHTML = sum;
				}
			}
		}
		function postnwes(){
			var maxdiv = document.getElementById('maxdiv');
			var ajax = new XMLHttpRequest();
			ajax.open('POST','https://api.apiopen.top/getWangYiNews');
			ajax.setRequestHeader('Content-type','application/x-www-form-urlencoded');
			ajax.send('page=2&count=5');			
			ajax.onreadystatechange = function(){
				if(ajax.status == 200 && ajax.readyState==4){
					var obj = JSON.parse(ajax.responseText);
					var sum = '';
					console.log(obj.result);
					
					for(var i=0;i<obj.result.length;i++){
						sum = sum + `<a href="`+obj.result[i].path+`">`+obj.result[i].title+`</a>`+`<br/>`+obj.result[0].passtime+`<br/>`;
					}
					
					maxdiv.innerHTML = sum;
				}
			}
		}
	</script>
</html>
